const Router = require('koa-router')
const router = new Router()
const callCloudDB = require('../utils/callCloudDB.js')
const cloudStorage = require('../utils/callCloudStorage.js')

router.get('/list', async (ctx, next) => {
    const params = ctx.request.query
    // console.log(params)
    const query = `
        db.collection('user').skip(${params.start}).limit(${params.count}).get()
    `
    const res = await callCloudDB(ctx, 'databasequery', query)
    // console.log(res.data)
    const data = res.data
    let returnData = []
    for (let i = 0, len = data.length; i < len; i++) {
        returnData.push({
            _id: JSON.parse(data[i])._id,
            avatarUrl: JSON.parse(data[i]).avatarUrl,
            nickName: JSON.parse(data[i]).nickName,
            level: JSON.parse(data[i]).level,
            totalPoints: JSON.parse(data[i]).totalPoints,
        })
    }
    // console.log(returnData)

    ctx.body = {
        data: returnData,
        code: 20000,
    }
})

module.exports = router

